package com.shuhua.taskServer.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shuhua.pojo.entity.BankCard;

import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface BankCardMapper extends BaseMapper<BankCard> {
    @Select("SELECT " +
            "id, craftsman_id, bank_name, card_number, real_name, " +
            "card_state, is_default, created_at " +
            "FROM craftsman_bank_card " +
            "WHERE craftsman_id = #{craftsmanId} " )
    List<BankCard> selectCardsByUserId(@Param("craftsmanId") Integer craftsmanId);

    @Insert("INSERT INTO craftsman_bank_card (craftsman_id, bank_name, card_number, real_name, card_state, is_default, created_at) " +
            "VALUES (#{craftsmanId}, #{bankName}, #{cardNumber}, #{realName}, #{cardState}, #{isDefault}, #{createAt})")
    public int insertBankCard(BankCard bankCard);

    @Select("SELECT * FROM craftsman_bank_card WHERE card_number = #{cardNumber}")
    BankCard selectByCardNumber(@Param("cardNumber") String cardNumber);

    @Delete("DELETE FROM craftsman_bank_card WHERE card_number = #{cardNumber}")
    int deleteByCardNumber(@Param("cardNumber") String cardNumber);


}
